<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta
            content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"
            name="viewport">
    <title>Title</title>
    <style>
    </style>
    <script src="mobilescan/js/jquery-1.12.4.min.js"></script>
    <script src="mobilescan/js/parentpage.js"></script>
</head>
<body>
<div>1.html</div>
<div>
    <button id="go">1</button>
</div>
<iframe id="iframe" src="2.html"></iframe>
<script type="text/javascript">

    var parentpage = new ParentPage("webar");
    //公开一个服务
    parentpage.publishService('getCamPic', function (options, callback) {
        setTimeout(function () {
            callback({base64: '123', type: 'jpg'});
        }, 1000)
    })
    //公开一个事件，允许子页面被通知到
    parentpage.publishEvent('onCameraReady');
    setTimeout(function () {
        //发起事件通知
        parentpage.onCameraReady({name: 'cd'});
        //调用子页面的服务
        parentpage.childs['child2'].calcSum({a: 40, b: 60}, function (res) {
            console.log("父页面收到子页面的calcSum结果:" + JSON.stringify(res));
        })
    }, 3000)


</script>
</body>
</html>
